package com.yaozheng.vocationaltraining.fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.HomeActivity;
import com.yaozheng.vocationaltraining.adapter.CarTypeDetailListAdapter;
import com.yaozheng.vocationaltraining.adapter.RepaymentPeriodListAdapter;
import com.yaozheng.vocationaltraining.bean.CarDetailBean;
import com.yaozheng.vocationaltraining.bean.CarTypeBean;
import com.yaozheng.vocationaltraining.bean.DownPaymentBean;
import com.yaozheng.vocationaltraining.bean.RepaymentReriodBean;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by moon on 2017/11/22.
 */
@EFragment(R.layout.activity_repayment_period)
public class RepaymentPeriodFragment extends BaseFragment {
    public CarDetailBean getCarDetailBean() {
        return carDetailBean;
    }

    public void setCarDetailBean(CarDetailBean carDetailBean) {
        this.carDetailBean = carDetailBean;
    }

    CarDetailBean carDetailBean;

    public ArrayList<RepaymentReriodBean> getRePaymentPeriodBeanList() {
        return rePaymentPeriodBeanList;
    }

    public void setRePaymentPeriodBeanList(ArrayList<RepaymentReriodBean> rePaymentPeriodBeanList) {
        this.rePaymentPeriodBeanList = rePaymentPeriodBeanList;
    }

    ArrayList<RepaymentReriodBean> rePaymentPeriodBeanList = new ArrayList<>();


    @ViewById
    ListView listView;

    LayoutInflater inflater;
    @ViewById
    TextView headTitleText;

    RepaymentPeriodListAdapter repaymentPeriodListAdapter;

    @AfterViews
    public void initView() {
        headTitleText.setText("还款年限");
        inflater = this.getActivity().getLayoutInflater();

        repaymentPeriodListAdapter = new RepaymentPeriodListAdapter(this.getActivity(),
                PriceFragment.rePaymentPeriodBeanList);
        listView.setAdapter(repaymentPeriodListAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                repaymentPeriodListAdapter.setselectedPosition(i);

                for(RepaymentReriodBean bean : PriceFragment.rePaymentPeriodBeanList){
                    bean.setDefault(false);
                    bean.setDefaultValue(0);
                }
                PriceFragment.rePaymentPeriodBeanList
                        .get(i).setDefault(true);
                PriceFragment.rePaymentPeriodBeanList.get(i).setDefaultValue(1);
                ((HomeActivity)RepaymentPeriodFragment.this.getActivity()).backClick();
            }
        });



    }




}
